package connection;

import java.util.EventObject;

@SuppressWarnings("serial")
public class IrcEvent extends EventObject {
	public static int PRIVMESSAGE=1;
	public static int JOIN=2;
	public static int PART=3;
	
	private String[] msg;
	private String target=null;
	private String privMessage=null;
	private String firstWord=null;
	private String rest=null;
	
	public IrcEvent(Object source, String[] msg) {
		super(source);
		this.msg = msg;
		
		if (msg[1].equals("PRIVMSG")) {
			target=msg[2].substring(0, msg[2].indexOf(' '));
			if (!target.startsWith("#")) {
				target=msg[0].substring(0, msg[0].indexOf('!'));
			}
			
			privMessage = msg[2].substring(msg[2].indexOf(" :")+2);
			
			int spaceIndex = privMessage.indexOf(' ');
			if (spaceIndex != -1) {
				firstWord = privMessage.substring(0, spaceIndex);
			} else {
				firstWord = privMessage;
			}
			
			if (privMessage.length() > firstWord.length()) {
				rest = privMessage.substring(firstWord.length()+1);
			} else {
				rest = null;
			}
		}
	}
	
	public String getAuthor() {
		return msg[0];
	}
	public String getCommand() {
		return msg[1];
	}
	public String getArgs() {
		return msg[2];
	}
	public String getQuery() {
		return msg[0]+" "+msg[1]+" "+msg[2];
	}
	public String getTarget() {
		return target;
	}
	public String getPrivMessage() {
		return privMessage;
	}
	public String getFirstWord() {
		return firstWord;
	}
	public String getPrivRest() {
		return rest;
	}
}
